-
Notifications
You must be signed in to change notification settings - Fork 12.9k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add MVP suggestion for unsafe_op_in_unsafe_fn
#99827
Add MVP suggestion for unsafe_op_in_unsafe_fn
#99827
Conversation
Some changes occurred to MIR optimizations cc @rust-lang/wg-mir-opt |
r? @jackh726 (rust-highfive has picked a reviewer for you, use r? to override) |
err.multipart_suggestion_verbose( | ||
"consider wrapping the function in an unsafe block", | ||
suggestion, | ||
Applicability::MaybeIncorrect, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
perhaps HasPlaceholders?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The docs for Applicability
state
The suggestion cannot be applied automatically because it will not result in valid Rust code.
But I think the goal is to be able to apply a "quick fix" to make the code compile. Can HasPlaceholders
suggestion still be applied "auto-manually"? I have never used rustfix (:sweat_smile:) and I'm not sure how the different Applicability
settings behave for the end user.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maybe not, good point.
This is actually unsafeck, sorry for the pings everyone. Should MIR unsafeck be excluded from the notification group? |
I'm not so sure that we should recommend wrapping the entire function in an unsafe block. I believe the advice is still generally to reduce the scope of unsafe blocks as much as possible, and that should still apply here I think. |
At least in the past, I've gotten the sense that the clippy and to a greater extent the compiler only lint on and make suggestions for things where there is strong community consensus. I do not think there is consensus on where the scope of an unsafe block should go, so I think any suggestion made will be annoying to a significant fraction of users. |
@JakobDegen While that's true in general, based on discussion in the last lang meeting, we generally felt that:
Based on that, a coarse-grained block plus a mention of "or use finer-grained unsafe blocks" should be fine here, especially as a first pass. |
Hmm, ok. I'm not so sure I agree, but then I can't really say I'm a fan of the alternative either so it doesn't really make a difference to me |
LL | #![deny(unsafe_op_in_unsafe_fn)] | ||
| ^^^^^^^^^^^^^^^^^^^^^^ | ||
= note: consult the function's documentation for information on how to avoid undefined behavior | ||
help: consider wrapping the function in an unsafe block |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm not sure that this help text is useful -- I assume it's not necessary for the suggestion to be emitted for us to show it to humans too?
I feel like something more human-applicable here would be better, along the lines of "help: an unsafe function restricts callers, but it's body is safe by default". But I'm struggling with something succinct here.
It's probably a good idea to update the text in E0133 with some more expansive commentary on the effects of unsafe_op_in_unsafe_fn in any case, since it currently says nothing about that case.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm not sure that this help text is useful -- I assume it's not necessary for the suggestion to be emitted for us to show it to humans too?
We could show only the message without the code, or hide the suggestion entirely.
63e2854
to
7821c5d
Compare
This comment has been minimized.
This comment has been minimized.
7821c5d
to
c8e6001
Compare
This comment has been minimized.
This comment has been minimized.
c8e6001
to
ab2eef3
Compare
This comment has been minimized.
This comment has been minimized.
ab2eef3
to
1f75da0
Compare
☔ The latest upstream changes (presumably #100740) made this pull request unmergeable. Please resolve the merge conflicts. |
@LeSeulArtichaut changed this since it's marked Draft, but let me know if you'd rather have a review before continuing |
I won't have time to take care of this, sorry... |
…fn, r=petrochenkov Add details about `unsafe_op_in_unsafe_fn` to E0133 This was mentioned in rust-lang#99827 (comment)
Add MVP suggestion for `unsafe_op_in_unsafe_fn` Rebase of rust-lang#99827 cc tracking issue rust-lang#71668 No real changes since the original PR, just migrated the new suggestion to use fluent messages and added a couple more testcases, AFAICT from the discussion there were no outstanding changes requested.
Add MVP suggestion for `unsafe_op_in_unsafe_fn` Rebase of rust-lang/rust#99827 cc tracking issue rust-lang/rust#71668 No real changes since the original PR, just migrated the new suggestion to use fluent messages and added a couple more testcases, AFAICT from the discussion there were no outstanding changes requested.
Add MVP suggestion for `unsafe_op_in_unsafe_fn` Rebase of rust-lang/rust#99827 cc tracking issue rust-lang/rust#71668 No real changes since the original PR, just migrated the new suggestion to use fluent messages and added a couple more testcases, AFAICT from the discussion there were no outstanding changes requested.
Add MVP suggestion for `unsafe_op_in_unsafe_fn` Rebase of rust-lang/rust#99827 cc tracking issue rust-lang/rust#71668 No real changes since the original PR, just migrated the new suggestion to use fluent messages and added a couple more testcases, AFAICT from the discussion there were no outstanding changes requested.
cc tracking issue #71668